package com.yociyy.admin.controller;

import com.github.pagehelper.PageHelper;
import com.yociyy.admin.biz.BaseDictTypeBiz;
import com.yociyy.admin.model.entity.BaseDictType;
import com.yociyy.common.core.msg.R;
import com.yociyy.common.core.msg.TableR;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 字典类型
 * 
 * @author Y.yang
 * @date 2020/5/21
 */
@RestController
@RequestMapping("dict/type")
public class BaseDictTypeController {

	@Autowired
	private BaseDictTypeBiz baseDictTypeBiz;

	/**
	 * 根据字典类型ID查询信息
	 *
	 * @param id 字典类型ID
	 * @return 字典类型
	 */
	@GetMapping("/{id}")
	public BaseDictType get(@PathVariable("id") Long id) {
		return baseDictTypeBiz.selectDictTypeById(id);
	}

	/**
	 * 查询字典类型分页列表
	 *
	 * @param params 条件查询
	 * @return 字典类型列表
	 */
	@GetMapping("page")
	public TableR page(@RequestParam Map<String, Object> params) {
		PageHelper.startPage(params);
		return new TableR(baseDictTypeBiz.selectPage(params));
	}

	/**
	 * 新增字典类型
	 *
	 * @param baseDictType 字典类型信息
	 * @return 结果
	 */
	@PostMapping
	public R addDictType(@RequestBody BaseDictType baseDictType) {
		return R.success(baseDictTypeBiz.insertDictType(baseDictType));
	}

	/**
	 * 修改字典类型
	 *
	 * @param baseDictType 字典类型信息
	 * @return 结果
	 */
	@PutMapping
	public R putDictType(@RequestBody BaseDictType baseDictType) {
		return R.success(baseDictTypeBiz.updateDictType(baseDictType));
	}

	/**
	 * 删除字典类型
	 *
	 * @param ids id串
	 * @return 结果
	 */
	@DeleteMapping
	public R remove(String ids) {
		return R.success(baseDictTypeBiz.deleteDictTypeByIds(ids));
	}

}
